package com.gzz.socket.heartbeat;
import java.net.*;
/**
 * @description 客户端打印链接状态
 * @author csc
 */
public class DstClient {
    public static void main(String[] args) {
        try {
            Socket socket = new Socket("127.0.0.1", 30000);
            socket.setKeepAlive(true);
            socket.setSoTimeout(10);
            while (true) {
                socket.sendUrgentData(0xFF); // 发送心跳包
                // 心跳包只是用来检测socket的链接状态，并不会作为socket链接的通信内容，这点应当注意。
                System.out.println(socket.isBound());
                System.out.println(socket.isClosed());
                System.out.println(socket.isConnected());
                System.out.println(socket.isInputShutdown());
                System.out.println(socket.isOutputShutdown());
                System.out.println("------------我是分割线------------");
                Thread.sleep(3 * 1000);
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}